<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
				<block v-if="pageType!='3'">
					<u-form-item prop="needamount" label="贷款金额（万元）" label-width="auto">
						<u-input v-model="formData.amount" type="string" placeholder="请输入贷款金额" />
						<view slot="right">万元</view>
					</u-form-item>
					<u-form-item prop="needamount" label="贷款期限" label-width="auto">
						<u-input v-model="formData.term" type="number" placeholder="请输入贷款期限" />
						<view slot="right">期</view>
					</u-form-item>
					<u-form-item prop="needamount" label="利率" label-width="auto">
						<u-input v-model="formData.rate" type="string" placeholder="请输入利率" />
						<view slot="right">%</view>
					</u-form-item>
					<u-form-item prop="needdate" label="担保方式" label-width="auto">
						<u-input v-model="formData.method" type="string" placeholder="请输入担保方式" />
					</u-form-item>
					<u-form-item prop="needdesc" label="产品详情 " label-width="auto">
						<u-input type="textarea" v-model="formData.detail" placeholder="请输入产品详情" />
					</u-form-item>
					<u-form-item prop="lendingDate" label="放贷日期" label-width="auto" v-if="pageType=='1'">
						<dateTime v-model="formData.lendingDate" :showLabel="false" :showArrow="false" :required="false"
							:disabled="true" className="new-date-picker" placeholder="请选择放贷日期" jnpfKey="date">
						</dateTime>
					</u-form-item>
					<u-form-item prop="endDate" label="上笔结清日期" label-width="auto" v-if="pageType=='2'">
						<dateTime v-model="formData.endDate" :showLabel="false" :showArrow="false" :required="false"
							:disabled="true" className="new-date-picker" placeholder="请选择上笔结清日期" jnpfKey="date">
						</dateTime>
					</u-form-item>
					<u-form-item prop="lendingDate" label="续贷日期" label-width="auto" v-if="pageType=='2'">
						<dateTime v-model="formData.lendingDate" :showLabel="false" :showArrow="false" :required="false"
							:disabled="true" className="new-date-picker" placeholder="请选择续贷日期" jnpfKey="date">
						</dateTime>
					</u-form-item>
				</block>
				<block v-else>
					<u-form-item prop="endLendingAmount" label="结清金额（万元）" label-width="auto">
						<u-input v-model="formData.endLendingAmount" type="string" placeholder="请输入结清金额" />
						<view slot="right">万元</view>
					</u-form-item>
					<u-form-item prop="endDate" label="结清日期" label-width="auto" v-if="pageType=='3'">
						<dateTime v-model="formData.endDate" :showLabel="false" :showArrow="false" :required="false"
							:disabled="true" className="new-date-picker" placeholder="请选择续贷日期" jnpfKey="date">
						</dateTime>
					</u-form-item>
					<u-form-item prop="endLendingDesc" label="结清原因 " label-width="auto">
						<u-input type="textarea" v-model="formData.endLendingDesc" placeholder="请输入产品详情" />
					</u-form-item>
				</block>
				<u-form-item prop="images" label="附件信息" label-width="auto">
					<JNPFUpload v-model="attendanceFileList" :value="attendanceFileList" :fileSize='2' :limit='10'
						:showLabel="false" @uploading="uploading" @input="uploadInput">
					</JNPFUpload>
				</u-form-item>
			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" shape="circle" :disabled="btnDisabled" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import dateTime from '@/components/dateTime/dateTime.vue'

	import jnpf from '@/common/js/jnpf.js'
	import signUplpad from '@/pagesJiushi/customer/actualController/components/signUplpad.vue'
	export default {
		components: {
			signUplpad,
			dateTime
		},
		name: 'customerBase',
		data() {
			return {
				formData: {
					amount: undefined,
					term: undefined,
					rate: undefined,
					method: undefined,
					detail: undefined,
					number: 1,
					customerId: undefined,
					bankUserId: undefined,
					customerNeedId: undefined,
					customerNeedRecordId: undefined,
				},
				pageType: 1,
				attendanceFileList: [],
				apiUrl: '',
				btnDisabled: false,
				loandetailId: ''
			}
		},
		onLoad(options) {
			if (options.customerId) {
				this.formData.customerId = options.customerId;
			}
			if (options.recordId) {
				this.formData.customerNeedRecordId = options.recordId;
			}
			if (options.needId) {
				this.formData.customerNeedId = options.needId;
			}
			if (options.bankUserId) {
				this.formData.bankUserId = options.bankUserId;
			}
			if (options.id) {
				this.loandetailId = options.id;
			}
			if (options.type) {
				let tempType = options.type
				this.pageType = tempType
				let tempTitle = ''
				switch (tempType) {
					case "1":
						tempTitle = '放贷操作'
						this.apiUrl = "/api/Jiushi/Customerloandetail/Reviewer/" + this.loandetailId
						break;
					case "2":
						tempTitle = '续贷操作'
						this.apiUrl = "/api/Jiushi/Customerloandetail/RenewalLoan/" + this.loandetailId
						break;
					case "3":
						tempTitle = '结清操作'
						this.apiUrl = "/api/Jiushi/Customerloandetail/EndLending/" + this.loandetailId
						break;
				}
				uni.setNavigationBarTitle({
					title: tempTitle
				})
			}
		},
		methods: {
			//Serialid 
			uploading(flag) {
				this.btnDisabled = flag
			},
			/* 表单提交 */
			onSubmit() {
				this.formData.attachment = this.attendanceFileList.map(item => {
					return item.url
				}).join(',')
				this.$helper.ajax({
					url: this.apiUrl,
					method: 'PUT',
					contentType: "application/json",
					data: this.formData,
					success: res => {
						this.$helper.msg(res.data.msg, 'success');
						uni.setStorage({
							key: "refreshPage",
							data: true
						})
						uni.navigateBack({
							data: -1
						})
					}
				});
			}
		}
	}
</script>

<style>

</style>